package com.advanced;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-09-29 18:10:19
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-09-29     张李鑫                     1.0         1.0 Version
 */
public class OddEvenList {

    static class ListNode {
        int val;
        ListNode next;

        public ListNode(int val) {
            this.val = val;
        }

        public ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public static ListNode oddEvenList(ListNode head) {
        if (head == null || head.next == null || head.next.next == null) {
            return head;
        }
        ListNode listNode = head;
        ListNode f = head;
        ListNode s = head.next;
        ListNode end = s;
        ListNode start = head.next.next;
        while (start != null) {
            f.next = start;
            s.next = start.next;
            start = start.next == null ? null : start.next.next;
            f = f.next;
            s = s.next;
        }
        f.next = end;
        return listNode;
    }


    public static void main(String[] args) {
        ListNode listNode = new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5, null)))));

        ListNode listNode1 = oddEvenList(listNode);

        System.out.println(123);
    }
}

